<?php

/**
 * This is the model class for table "member".
 *
 * The followings are the available columns in table 'member':
 * @property integer $user_id
 * @property string $cmnd
 * @property string $fullname
 * @property integer $sex
 * @property string $birthday
 * @property string $birthplace
 * @property string $phone
 * @property string $cellphone
 * @property string $email
 * @property string $address
 * @property string $contact_address
 * @property string $avatar
 * @property string $social_position
 * @property string $social_activity
 * @property integer $status
 * @property string $donor_name
 * @property string $donor_address
 * @property string $donor_email
 *
 * The followings are the available model relations:
 * @property AnnouncementAssign[] $announcementAssigns
 * @property Users $user
 * @property MemberCode[] $memberCodes
 */
class MemberBase extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return MemberBase the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'member';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('cmnd, fullname, donor_name', 'required'),
			array('user_id, sex, status', 'numerical', 'integerOnly'=>true),
			array('cmnd', 'length', 'max'=>12),
			array('fullname, email, donor_name, donor_email', 'length', 'max'=>128),
			array('birthday', 'length', 'max'=>10),
			array('birthplace, address, contact_address, avatar, donor_address', 'length', 'max'=>255),
			array('phone, cellphone', 'length', 'max'=>20),
			array('social_position, social_activity', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_id, cmnd, fullname, sex, birthday, birthplace, phone, cellphone, email, address, contact_address, avatar, social_position, social_activity, status, donor_name, donor_address, donor_email', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'announcementAssigns' => array(self::HAS_MANY, 'AnnouncementAssign', 'member_id'),
			'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
			'memberCodes' => array(self::HAS_MANY, 'MemberCode', 'user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_id' => 'User',
			'cmnd' => 'Cmnd',
			'fullname' => 'Fullname',
			'sex' => 'Sex',
			'birthday' => 'Birthday',
			'birthplace' => 'Birthplace',
			'phone' => 'Phone',
			'cellphone' => 'Cellphone',
			'email' => 'Email',
			'address' => 'Address',
			'contact_address' => 'Contact Address',
			'avatar' => 'Avatar',
			'social_position' => 'Social Position',
			'social_activity' => 'Social Activity',
			'status' => 'Status',
			'donor_name' => 'Donor Name',
			'donor_address' => 'Donor Address',
			'donor_email' => 'Donor Email',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('cmnd',$this->cmnd,true);
		$criteria->compare('fullname',$this->fullname,true);
		$criteria->compare('sex',$this->sex);
		$criteria->compare('birthday',$this->birthday,true);
		$criteria->compare('birthplace',$this->birthplace,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('cellphone',$this->cellphone,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('contact_address',$this->contact_address,true);
		$criteria->compare('avatar',$this->avatar,true);
		$criteria->compare('social_position',$this->social_position,true);
		$criteria->compare('social_activity',$this->social_activity,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('donor_name',$this->donor_name,true);
		$criteria->compare('donor_address',$this->donor_address,true);
		$criteria->compare('donor_email',$this->donor_email,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}